package com.twu.biblioteca;

import java.util.List;

/**
 * Created by aswathik on 6/19/14.
 */
public class ListMovie implements MenuItem {
    private Library library;
    private String menuString;

    ListMovie(Library library) {
        this.library = library;
        menuString = "List Movie";
    }

    public String getMenuString() {
        return menuString;
    }



    public MenuActionResult performMenuAction(UserInterface userInterface) {

        List<LibraryItem> listOfAvailableMovies;
        MenuActionResult menuActionResult = new MenuActionResult();

        listOfAvailableMovies = library.getAvailableMovieList();

        userInterface.displayResultString(String.format("%-40s%-40s%-40s%-40s", "Title", "Director", "Year Of Publication","Rating"));
        userInterface.displayResultString("\n==================================================================================================================================");

        for ( int i = 0; i < listOfAvailableMovies.size(); i++)
            userInterface.displayLibraryItemDetails(listOfAvailableMovies.get(i));

        if ( listOfAvailableMovies.size() != 0) {
            menuActionResult.setMenuActionDetails(true,"List of movies are displayed");
        } else {
            menuActionResult.setMenuActionDetails(false, "Sorry there are no valid movies to display");
        }

        userInterface.displayMenuActionResult(menuActionResult);
        return menuActionResult;
    }
}

